package com.young.pattern.singletonPattern;

/**
 * 恶汉式单例类
 *  恶汉式单例类由于是定义静态变量的时候实例化单例类,因此在类加载时单例对象就已创建;
 *
 */
public class EagerSingleton {

    //  当类被加载时,静态变量instance会被初始化,此时类的私有构造函数会被调用,单例类的唯一实例将被创建.

    private static final EagerSingleton instance = new EagerSingleton();

    private EagerSingleton(){
    }

    public static EagerSingleton getInstance(){
        return instance;
    }
}
